import App from './selectorg.vue';
import Vue from 'vue';
import * as Fiber from 'fiber';
import store from '@/store';
import filters from '@/filters/selectPeople.js';

import '@/css/common.scss';

import CtpI18n from '@/utils/ctpI18n';
Vue.config.productionTip = false;

/**
 * 全局过滤器
 * 给需要选择的数据项绑定key
 */
Object.keys(filters).forEach((key) => {
	Vue.filter(key, filters[key]);
});

const selectDataToRight = (entities, notIncludeSubDept) => {
	return store.dispatch('selectData/ACTION_TOGGLE_ENTITY', {
		entities,
		notIncludeSubDept
	});
};

Vue.prototype.selectDataToRight = selectDataToRight;
Vue.prototype.dialogWindow = window;
Vue.use(Fiber);
Vue.use(CtpI18n);


// 记录页签上次加载数据[全局变量，不需要vue管理]
const panelAccountRecord = {};
/**
 *  判断页签数据是否发生改变
 * @param panelObj 页签
 * @param targetAccountId 目标单位
 * @returns {boolean}
 */
Vue.prototype.$isChangeAccount = (panelObj, targetAccountId) => {
	const panelName = panelObj.$options._componentTag;
	const isChangeAccount = !(panelAccountRecord[panelName] === targetAccountId);
	console.debug(`${panelName} $isChangeAccount:${isChangeAccount}  [current:${panelAccountRecord[panelName]} -- target:${targetAccountId}]`);
	return isChangeAccount;
};
/**
 * 更改页签单位
 * @param panelObj 页签
 * @param targetAccountId 目标单位
 * @returns {boolean}
 */
Vue.prototype.$changeAccount = (panelObj, targetAccountId) => {
	const panelName = panelObj.$options._componentTag;
	console.debug(`${panelName} $changeAccount: ${targetAccountId}`);
	panelAccountRecord[panelName] = targetAccountId;
};

const selectOrgRoot = new Vue({
	store,
	render: (h) => h(App)
}).$mount('#app');

selectOrgRoot.$message.config({ maxCount: 1 });
